﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Scrat.Core.Pojo
{
    /// <summary>
    /// 消息类型: string通过UTF8转换后的byte[]
    /// 文件类型的数据报: 文件全路径+文件大小
    /// 举手类型,直接调用无参构造
    /// </summary>
    [Serializable]
    public class Datagram
    {
        public static readonly Encoding ENCODING = Encoding.UTF8;

        private Identity _identity;
        private DataGramType _dataGramType;
        private object _data;

        // 发送身份
        public Identity Identity { get { return _identity; } set { _identity = value; } }
        // 数据的类型
        public DataGramType DataGramType { get { return _dataGramType; } set { _dataGramType = value; } }
        // 具体的数据
        public object Data { get { return _data; } set { _data = value; } }

        public IPAddress RemoteIPAddr { get; set; }
        public int RemotePort { get; set; }

        public Datagram(Identity identity, DataGramType dataGramType, object data)
        {
            Identity = identity;
            DataGramType = dataGramType;
            Data = data;
        }
    }

    public enum Identity
    {
        Student,
        Teacher,
        MySelf,
        Unknown
    }

    public enum DataGramType
    { 
        Online,// 上线, 只有学生发送,教师机只需要接收该类型
        Downline,// 下线
        Message,// 消息
        FileInfo,// 当发送文件时,需要提前发送文件信息, 询问对方是否接收
        RaisHands,// 学生特有的类型, 课堂举手
        RequireStuDemonstrate,
        OuterData// 为外部应用发送的数据
    }
}
